Commit 205c5164 by Sven Marnach

Add configuration option to decide whether image alt attrs should be mandatory.

parent b42291da
...@@ -121,8 +121,17 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin): ...@@ -121,8 +121,17 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin):
return [(key, {'label': markdown(value['label']), 'img': value['img'], 'img_alt': value.get('img_alt')}) return [(key, {'label': markdown(value['label']), 'img': value['img'], 'img_alt': value.get('img_alt')})
for key, value in items] for key, value in items]
@staticmethod def img_alt_mandatory(self):
def gather_items(data, result, noun, field, image=True): """
Determine whether alt attributes for images are configured to be mandatory. Defaults to True.
"""
settings_service = self.runtime.service(self, "settings")
if not settings_service:
return True
xblock_settings = settings_service.get_settings_bucket(self)
return xblock_settings.get('IMG_ALT_MANDATORY', True)
def gather_items(self, data, result, noun, field, image=True):
""" """
Gathers a set of label-img pairs from a data dict and puts them in order. Gathers a set of label-img pairs from a data dict and puts them in order.
""" """
...@@ -165,6 +174,11 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin): ...@@ -165,6 +174,11 @@ class PollBase(XBlock, ResourceMixin, PublishEventMixin):
"All {1}s must have labels. Please check the form. " "All {1}s must have labels. Please check the form. "
"Check the form and explicitly delete {1}s " "Check the form and explicitly delete {1}s "
"if not needed.".format(noun, noun.lower())) "if not needed.".format(noun, noun.lower()))
if image_link and not image_alt and self.img_alt_mandatory():
result['success'] = False
result['errors'].append(
"All images must have an alternative text describing the image in a way that "
"would allow someone to answer the poll if the image did not load.")
if image: if image:
items.append((key, {'label': label, 'img': image_link, 'img_alt': image_alt})) items.append((key, {'label': label, 'img': image_link, 'img_alt': image_alt}))
else: else:
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
{{#if image}} {{#if image}}
<label class="label setting-label" for="{{noun}}-img-{{key}}">Image URL</label> <label class="label setting-label" for="{{noun}}-img-{{key}}">Image URL</label>
<input class="input setting-input" name="{{noun}}-img-{{key}}" id="{{noun}}-img-{{key}}" value="{{img}}" type="text" /><br /> <input class="input setting-input" name="{{noun}}-img-{{key}}" id="{{noun}}-img-{{key}}" value="{{img}}" type="text" /><br />
<label class="label setting-label" for="{{noun}}-img_alt-{{key}}">Image alternate text</label> <label class="label setting-label" for="{{noun}}-img_alt-{{key}}">Image alternative text</label>
<input class="input setting-input" name="{{noun}}-img_alt-{{key}}" id="{{noun}}-img_alt-{{key}}" value="{{img_alt}}" type="text" /><br /> <input class="input setting-input" name="{{noun}}-img_alt-{{key}}" id="{{noun}}-img_alt-{{key}}" value="{{img_alt}}" type="text" /><br />
{{/if}} {{/if}}
</div> </div>
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
</span> </span>
<span class="tip setting-help"> <span class="tip setting-help">
{{#if image}} {{#if image}}
This must have an image URL or text, and can have both. If you add an image, an alternate text that describes This must have an image URL or text, and can have both. If you add an image, you must also provide an alternative text
the image in a way that would allow someone to answer the poll if the image did not load is strongly encouraged. that describes the image in a way that would allow someone to answer the poll if the image did not load.
{{/if}} {{/if}}
</span> </span>
</li> </li>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment